package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsBrandMapper;
import com.qf.mapper.DtsStorageMapper;
import com.qf.pojo.DtsAdmin;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsCategory;
import com.qf.pojo.DtsStorage;
import com.qf.service.DtsAdminService;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsCategoryService;
import com.qf.util.ResponseUtil;
import com.qf.vo.CatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName:shop_manage
 * author:hzq
 * time:2021/11/30 17:38
 * description:品牌管理商
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/admin/brand")
public class AdminBrandController {

    @Autowired
    DtsBrandService brandService;

    @Autowired
    DtsAdminService adminService;

    @Autowired
    DtsCategoryService categoryService;

    @Autowired
    DtsStorageMapper storageMapper;

    @Autowired
    DtsBrandMapper brandMapper;

    @RequestMapping("update")
    public Object update(@RequestBody DtsBrand brand){

        return brandService.updateBrand(brand);
    }

    @RequestMapping("delete")
    public Object delete(@RequestBody DtsBrand brand){
       return brandService.deleteBrand(brand);
    }
    @RequestMapping("create")
    public Object create(@RequestBody DtsBrand brand){

        return brandService.insertBrand(brand);

    }

    @RequestMapping("catAndAdmin")
    public Object catAndAdmin(){
        List<Map<String,Object>> adminList = adminService.findAdminList();
        List<CatVo> categoryList= categoryService.findCategoryList();

        Map<String,Object> data = new HashMap<>();
        data.put("adminList",adminList);
        data.put("categoryList",categoryList);
        return ResponseUtil.ok(data);
    }
    @RequestMapping("list")
    public Object list(
            @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
            @RequestParam(name = "limit",required = false,defaultValue = "20") Integer limit,
            Integer id,
            String name,
            @RequestParam(name = "sort",required = false,defaultValue = "add_time") String sort,
            @RequestParam(name = "order",required = false,defaultValue = "asc") String order
    ){
        IPage<Map<String,Object>> ipage = brandService.findPage(page,limit,id,name,sort,order);

        Map<String,Object> data = new HashMap<>();
        data.put("total",ipage.getTotal());
        data.put("items",ipage.getRecords());
        return ResponseUtil.ok(data);

    }
}